from socket import *
import struct

u_server = socket(AF_INET, SOCK_DGRAM)
u_server.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
f=open("student_list.txt", "a+")
u_server.bind(('127.0.0.1', 9999))
while True:
    data, addr = u_server.recvfrom(1024)
    data_from_client = struct.unpack("i10sfi", data)
    ls=[]
    for item in data_from_client:
        if type(item) == int or type(item) ==float:
            ls.append(item)
        else:
            ls.append(item.strip(b"\x00").decode("utf-8"))
    data_to_write="%d  %-10s %.f %d"%tuple(ls)
    f.write(f"{data_to_write}\n")
    f.flush()
    u_server.sendto(b"server accept", addr)
